import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created with IntelliJ IDEA.
 * Description:Callable接口
 * User: 东莞呵呵
 * Date:2022-09-29
 * Time:13:03
 */
public class Demo15 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int count = 0;
                synchronized (this) {
                    for (int i = 0; i < 50000; i++) {
                        count++;
                    }
                }
                return count;
            }
        };
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        FutureTask<Integer> futureTask2 = new FutureTask<>(callable);
        Thread t1 = new Thread(futureTask);
        Thread t2 = new Thread(futureTask2);



        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(futureTask.get()+futureTask2.get());
    }
}
